package com.xca.znb.presenter;

import com.xca.znb.entity.Message;
import com.xca.znb.entity.NewsLetter;
import com.xca.znb.entity.User;
import com.xca.znb.model.imodel.IMessage;

import java.util.List;

public class MessagePresenter {
    private IMessage iMessage ;
    public MessagePresenter(IMessage iMessage){
        this.iMessage = iMessage ;
    }

    public void sendMessage(String sendId, String receiveId, String text, String time){
        iMessage.sendMessage(sendId, receiveId, text, time);
        NewsLetter newsLetter = iMessage.getNewsletterByPhone(sendId,receiveId);
        NewsLetter newsLetter1 = iMessage.getNewsletterByPhone(receiveId,sendId);
        if (newsLetter != null){
            iMessage.updateNewsletterTimeByPhone(sendId,receiveId,time);
        } else if (newsLetter1 != null) {
            iMessage.updateNewsletterTimeByPhone(receiveId ,sendId ,time);
        }
    }
    public List<Message> getMessage(){
        return iMessage.getMessage();
    }
    public User getUserByPhone(String phone){
        return iMessage.getUserByPhone(phone);
    }
}
